package cn.hzking.gjmall.activitys.my;

import android.support.design.widget.TabLayout;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.hzking.gjmall.R;
import cn.hzking.gjmall.base.ColorStatuBarActivity;
import cn.hzking.gjmall.delegates.my.MyCouponDelegate;

public class MyCouponActivity extends ColorStatuBarActivity {
    public static final int UNUSED = 1;//未使用
    public static final int USED = 2;//已使用
    public static final int OVERTIME = 3;//已过期
    @Bind(R.id.rl_back) RelativeLayout backRl;
    @Bind(R.id.vp) ViewPager vp;
    @Bind(R.id.tb) TabLayout tb;
    private List<MyCouponDelegate> list;
    private String[] titles = new String[]{"未使用", "已使用", "已过期"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_my_coupon);
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
        init();
    }

    private void init() {
        list=new ArrayList<>();
        MyCouponDelegate unusedcoupon=MyCouponDelegate.newInstance(UNUSED);
        MyCouponDelegate usedcoupon=MyCouponDelegate.newInstance(USED);
        MyCouponDelegate overtimecoupon=MyCouponDelegate.newInstance(OVERTIME);
        list.add(unusedcoupon);
        list.add(usedcoupon);
        list.add(overtimecoupon);

        vp.setAdapter(new ViewPagerAdapter(getSupportFragmentManager()));
        tb.setupWithViewPager(vp);
        vp.setOffscreenPageLimit(3);
        backRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }
    class ViewPagerAdapter extends FragmentPagerAdapter {

        public ViewPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public MyCouponDelegate getItem(int position) {
            return list.get(position);
        }

        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return titles[position];
        }
    }
}
